﻿using EFCore.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SService;

namespace WMSWeb.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehouseController : ControllerBase
    {
        private readonly WmssystemContext myDb;
        private readonly WarehouseS warehouseS;

        public WarehouseController(WmssystemContext myDb, SService.WarehouseS  warehouseS)
        {
            this.myDb = myDb;
            this.warehouseS = warehouseS;
        }
        /// <summary>
        /// 仓库管理查询全部
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public Task<List<Sys_warehouse>> Wqu()
        {
            return warehouseS.Wqu();
        }
        /// <summary>
        /// 仓库管理分页模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("FenYe")]
        public async Task<List<Sys_warehouse>> FenYe(int pageSize, int currentPage, string key = null, int? Status = null)
        {
            return await warehouseS.FenYe(pageSize, currentPage, key, Status);
        }
        /// <summary>
        /// 仓库管理状态修改
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdStatus")]
        public async Task<ActionResult<int>> UpdStatus(int id, int status)
        {
            return await warehouseS.UpdStatus(id, status);
        }
        /// <summary>
        /// 仓库管理添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<int>> Add(Sys_warehouse add)
        {
            // 为实体的属性赋值
            add.w_wisdelete = 1;
            // 调用服务层的方法执行添加操作
            return await warehouseS.Add(add);
        }
        /// <summary>
        /// 仓库管理逻辑删除
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdIsDelete")]
        public async Task<ActionResult<int>> UpdIsDelete(int id, int isDeleted)
        {
            return await warehouseS.UpdIsDelete(id, isDeleted);
        }
        /// <summary>
        /// 仓库管理修改
        /// </summary>
        /// <returns></returns>
        [HttpPut("Upd")]
        public async Task<int> Upd(Sys_warehouse upd)
        {
            upd.w_wupdateuser = 1;
            upd.w_wcreatetime = new DateTime();

            return await warehouseS.Upd(upd);
        }
    }
}
